<div class="page_basic">
  <%= render("_nav.html", assigns) %>

  <div class="flash flash--inline flash--success">
    <div class="flash-message">
  <%= if @current_user.public_profile do %>
    <p>Your <%= link("public profile", to: PersonView.profile_path(@current_user)) %> page shows news you've contributed and podcasts you've been on.</p>
  <% else %>
    <p>Profiles pages show news you've contributed and podcasts you've been on. Your profile is private.</p>
  <% end %>
    </div>
  </div>

  <%= form_for @changeset, Routes.home_path(@conn, :update), [class: "form", multipart: true], fn f -> %>
    <input type="hidden" name="from" value="profile">

    <div class="form-element_wrap form-element_wrap--2">
      <div class="form-element <%= PublicHelpers.error_class(f, :name) %>">
        <label>Name<span>*</span></label>
        <%= text_input(f, :name, placeholder: "Grace Hopper") %>
        <%= PublicHelpers.error_message(f, :name) %>
      </div>

      <div class="form-element <%= PublicHelpers.error_class(f, :handle) %>">
        <label>Username / Handle<span>*</span></label>
        <%= text_input(f, :handle, placeholder: "gracehopper", autocapitalize: "none") %>
        <%= PublicHelpers.error_message(f, :handle) %>
      </div>
    </div>

    <div class="form-element_wrap form-element_wrap--2">
      <div class="form-element <%= PublicHelpers.error_class(f, :avatar) %>">
        <label>Avatar</label>
        <%= file_input(f, :avatar) %>
        <%= PublicHelpers.error_message(f, :avatar) %>
        <p class="form-element-note">Ideally 600px by 600px. We'll crop it square.</p>
      </div>

      <div class="form-element">
        <%= SharedHelpers.maybe_lazy_image(@conn, PersonView.avatar_url(@changeset.data), @changeset.data.name, width: 67, height: 67) %>
        <p class="form-element-note"><%= if @changeset.data.avatar, do: "This image was uploaded to changelog.com", else: "This image is loaded from Gravatar" %>
      </div>
    </div>

    <div class="form-element_wrap form-element_wrap--3">
      <div class="form-element <%= PublicHelpers.error_class(f, :github_handle) %>">
        <label>GitHub Handle</label>
        <div class="form-element-preppended_field">
          <span>github.com/</span>
          <%= text_input(f, :github_handle, placeholder: "gracehopper", autocapitalize: "none") %>
        </div>
        <%= PublicHelpers.error_message(f, :github_handle) %>
      </div>

      <div class="form-element <%= PublicHelpers.error_class(f, :twitter_handle) %>">
        <label>Twitter Handle</label>
        <div class="form-element-preppended_field">
          <span>twitter.com/</span>
          <%= text_input(f, :twitter_handle, placeholder: "gracehopper", autocapitalize: "none") %>
        </div>
        <%= PublicHelpers.error_message(f, :twitter_handle) %>
      </div>

      <div class="form-element <%= PublicHelpers.error_class(f, :linkedin_handle) %>">
        <label>LinkedIn Handle</label>
        <div class="form-element-preppended_field">
          <span>linked.com/in/</span>
          <%= text_input(f, :linkedin_handle, placeholder: "gracehopper", autocapitalize: "none") %>
        </div>
        <%= PublicHelpers.error_message(f, :linkedin_handle) %>
      </div>
    </div>

    <div class="form-element_wrap form-element_wrap--3">
      <div class="form-element <%= PublicHelpers.error_class(f, :mastodon_handle) %>">
        <label>Mastodon Handle</label>
        <div class="form-element-preppended_field">
          <span>@</span>
          <%= text_input(f, :mastodon_handle, placeholder: "gracehopper@changelog.social") %>
        </div>
        <%= PublicHelpers.error_message(f, :mastodon_handle) %>
      </div>

      <div class="form-element <%= PublicHelpers.error_class(f, :location) %>">
        <label>Location</label>
        <%= text_input(f, :location, placeholder: "New York, New York") %>
        <%= PublicHelpers.error_message(f, :location) %>
      </div>

      <div class="form-element <%= PublicHelpers.error_class(f, :website) %>">
        <label>Website URL</label>
        <%= text_input(f, :website, placeholder: "https://gracehopper.com", autocapitalize: "none") %>
        <%= PublicHelpers.error_message(f, :website) %>
      </div>
    </div>

    <div class="form-element_wrap">
      <div class="form-element <%= PublicHelpers.error_class(f, :bio) %>">
        <label>Bio</label>
        <%= textarea(f, :bio) %>
        <%= PublicHelpers.error_message(f, :bio) %>
        <p class="form-element-note">Markdown FTW</p>
      </div>
    </div>

    <div class="form-checklist">
      <div class="form-checklist-item <%= PublicHelpers.error_class(f, :public_profile) %>">
      <%= if Changelog.Policies.Person.profile(@current_user, @current_user) do %>
        <label>
          <%= checkbox(f, :public_profile) %>
          <span class="form-checklist-item-box"></span>
          <span class="form-checklist-item-text">I want a public profile page.</span>
        </label>
      <% else %>
        <label>
          <%= checkbox(f, :public_profile, disabled: true) %>
          <span class="form-checklist-item-box"></span>
          <span class="form-checklist-item-text">I want a public profile page.</span>
        </label>

        <p class="form-element-note">We have to approve something you publish first. <%= link("Submit", to: Routes.news_item_path(@conn, :new)) %> some news or <%= link("request", to: Routes.episode_request_path(@conn, :new)) %> an episode to get started.</p>
      <% end %>
      </div>
    </div>

    <div class="form-submit">
      <p class="form-submit-toc">By creating a public profile you agree to our <a href="/coc">code of conduct</a>, <a href="/privacy">privacy</a>, and <a href="/terms">terms</a>.</p>
      <div>
        <input type="submit" value="Update Profile">
        <div class="form_submit_responses"></div>
      </div>
    </div>
  <% end %>
</div>
